﻿using System;
using System.Data;
using ET;
using Ext.Net;
using BLL;
using Roles;

namespace ERP.Modules
{
    public partial class Export : System.Web.UI.UserControl
    {
        private readonly Export_BLL clsExport = new Export_BLL();
        private readonly Warehouse_BLL _clsWarehouse = new Warehouse_BLL();
        private readonly Room_BLL _clsRoom = new Room_BLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                CheckPermisstion();
                GetData();
                GetRoom();
                GetWarehouse();
                GetComboBox();
                ClearTextBox();
                WindowsBranch();
                WindowsWarehouse();
                WindowsRoom();
            }
        }
        //-------Store-Datasource-----------------
        protected void StoreExport_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            txtSearch.Text = string.Empty;
            txtDateBeginFillter.Text = string.Empty;
            txtDateEndFillter.Text = string.Empty;
            SelectBoxExportWarrehouse.Text = string.Empty;
            SelectBoxExportRoom.Text = string.Empty;
            GetData();
            GetRoom();
            GetWarehouse();
        }
        protected void StoreExport_Detail_RefreshData(object sender, StoreReadDataEventArgs e)
        {

        }
        //--------Buttom-Main------------------------
        protected void btnAddNew_Click(object sender, DirectEventArgs e)
        {
            ClearTextBox();
            GetExport_Materials_Edit(0);
            WindowsExport.Show();
        }
        protected void btnEdit_Click(object sender, DirectEventArgs e)
        {
            var sm = grExport.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (SelectedRow row in sm.SelectedRows)
                {
                    ClearTextBox();
                    DataDetail(int.Parse(row.RecordID));
                    GetExport_Materials(int.Parse(row.RecordID));
                    WindowsExport.Show();
                    sm.UpdateSelection();
                }
        }
        protected void btnDel_Click(object sender, DirectEventArgs e)
        {
            var sm = grExport.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (SelectedRow row in sm.SelectedRows)
                {
                    var dt = clsExport.BindGirdtb_ExportDetail(int.Parse(row.RecordID));
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        if (String.IsNullOrEmpty(dt.Rows[0]["Lock"].ToString()))
                        {
                            try
                            {
                                Export_BLL.Deletetb_Export(int.Parse(row.RecordID));
                            }
                            catch (Exception)
                            {
                                HTML.clsFormat.Alert_ERROR("Thông Báo",
                                    "Tồn tại tài liệu con, không xoá được vui lòng xoá tài liệu con trước !");
                            }
                        }
                        else
                        {
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Phiếu xuất kho này đã được chốt, không xóa được!");
                        }
                    }
                }
            GetData();
        }
        protected void btnFillter_Click(object sender, DirectEventArgs e)
        {
            GetExportFillterDate();
        }
        protected void SelectBoxExportWarrehouse_Change(object sender, DirectEventArgs e)
        {
            SelectBoxExportRoom.Text = string.Empty;
            GetData();
        }
        protected void SelectBoxExportRoom_Change(object sender, DirectEventArgs e)
        {
            SelectBoxExportWarrehouse.Text = string.Empty;
            GetData();
        }
        //--------Buttom-Popup------------------------
        protected void btnSavePopUp_Click(object sender, DirectEventArgs e)
        {
            if (txtExport_ID.Text == string.Empty)
            {
                try
                {
                    if (!CheckInsert())
                    {
                        var GetExport_Detail = e.ExtraParams["grExport_Detail"];

                        var dtExport_Detail = JSON.Deserialize<DataTable>(GetExport_Detail);

                        if (dtExport_Detail.Rows.Count == 0)
                        {
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm để nhập kho !");
                        }
                        else
                        {
                            var obj = new Export_ET
                            {
                                Export_No = txtExport_No.Text,
                                Export_Date = DateTime.Parse(txtExport_Date.Text),
                                Export_Purcharse = txtExport_Provider.Text,
                                Proposed_Export_ID = int.Parse(txtProposed_Export_ID.Text),
                                Room_ID = cbRoom.SelectedItem.Value != null ? int.Parse(cbRoom.SelectedItem.Value) : (int?)null,
                                Warehouse_ID = int.Parse(cbWarehouse.SelectedItem.Value),
                                Export_Note = txtExport_Note.Text,
                                Export_Test = txtExport_Test.Text,
                                Export_Date_Add = DateTime.Now,
                                Export_Computer_Add = Environment.MachineName
                            };
                            var insert = Export_BLL.Inserttb_Export(obj);
                            if (insert)
                            {
                                foreach (DataRow rows in dtExport_Detail.Rows)
                                {
                                    var Export_Detail = new Export_Detail_ET
                                    {
                                        Export_ID = obj.Export_ID,
                                        Materials_ID = int.Parse(rows["Materials_ID"].ToString()),
                                        Export_Detail_Quality_Voucher = int.Parse(rows["Export_Detail_Quality_Voucher"].ToString()),
                                        Export_Detail_Quality_HaveExport = int.Parse(rows["Export_Detail_Quality_Insert"].ToString()),
                                        Export_Detail_Quality = int.Parse(txtProposed_Export_ID.Text),
                                        Export_Detail_Price = int.Parse(rows["Export_Detail_Price"].ToString())
                                    };
                                    Export_Detail_BLL.Inserttb_Export_Detail(Export_Detail);
                                }
                                HTML.clsFormat.Alert_INFO("Thông Báo", "Thêm mới thành công !");
                                grExport_Detail.GetStore().RemoveAll();
                                GetData();
                                ClearTextBox();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
                }
            }
            else
            {
                if (CheckPermisstionDobclick())
                {
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Bạn không được cấp quyền để sửa đổi !");
                }
                else
                {
                    try
                    {
                        if (!CheckInsert())
                        {
                            var GetExport_Detail = e.ExtraParams["grExport_Detail"];

                            var dtExport_Detail = JSON.Deserialize<DataTable>(GetExport_Detail);

                            if (dtExport_Detail.Rows.Count == 0)
                            {
                                HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm để nhập kho !");
                            }
                            else
                            {
                                var obj = new Export_ET
                                {
                                    Export_ID = int.Parse(txtExport_ID.Text),
                                    Export_No = txtExport_No.Text,
                                    Export_Date = DateTime.Parse(txtExport_Date.Text),
                                    Export_Purcharse = txtExport_Provider.Text,
                                    Proposed_Export_ID = int.Parse(txtProposed_Export_ID.Text),
                                    Room_ID = cbRoom.SelectedItem.Value != null ? int.Parse(cbRoom.SelectedItem.Value) : (int?)null,
                                    Warehouse_ID = int.Parse(cbWarehouse.SelectedItem.Value),
                                    Export_Note = txtExport_Note.Text,
                                    Export_Test = txtExport_Test.Text,
                                    Export_Date_Modify = DateTime.Now,
                                    Export_Computer_Modify = Environment.MachineName
                                };
                                bool update = Export_BLL.Updatetb_Export(obj);
                                if (update)
                                {
                                    Export_Detail_BLL.Deletetb_Export_Detail_Default_ID(int.Parse(txtExport_ID.Text));
                                    foreach (DataRow rows in dtExport_Detail.Rows)
                                    {
                                        var Export_Detail = new Export_Detail_ET
                                        {
                                            Export_ID = int.Parse(txtExport_ID.Text),
                                            Materials_ID = int.Parse(rows["Materials_ID"].ToString()),
                                            Export_Detail_Quality_Voucher = int.Parse(rows["Export_Detail_Quality_Voucher"].ToString()),
                                            Export_Detail_Quality_HaveExport = int.Parse(rows["Export_Detail_Quality_HaveExport"].ToString()) + int.Parse(rows["Export_Detail_Quality_Insert"].ToString()),
                                            Export_Detail_Quality = int.Parse(txtProposed_Export_ID.Text),
                                            Export_Detail_Price = int.Parse(rows["Export_Detail_Price"].ToString())
                                        };
                                        Export_Detail_BLL.Inserttb_Export_Detail(Export_Detail);
                                    }
                                    WindowsExport.Close();
                                    HTML.clsFormat.Alert_INFO("Thông Báo", "Sửa thành công!");
                                    GetData();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        HTML.clsFormat.Alert_ERROR("Lỗi", ex.ToString());
                    }
                }
            }
        }
        protected void btnCancelPopUp_Click(object sender, DirectEventArgs e)
        {
            WindowsExport.Close();
        }
        protected void btnAddExportMaterials_Click(object sender, DirectEventArgs e)
        {
            if (cbWarehouse.SelectedItem.Value != null)
            {
                cbProposed_Export.Clear();
                GetProposed_Export();
                StoreExport_Proposed_Export_Materials.Reload();
                WindowExport_Proposed_Export_Materials.Show();
            }
            else
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", "Vui lòng chọn kho trước khi xuất kho");
            }
        }
        //----------Click-------------------
        protected void Cell_Click(object sender, DirectEventArgs e)
        {

        }
        protected void ExportDblClick(object sender, DirectEventArgs e)
        {
            ClearTextBox();
            int Export_Id = int.Parse(e.ExtraParams["Export_ID"]);
            DataDetail(Export_Id);
            GetExport_Materials_Edit(Export_Id);
            WindowsExport.Show();
        }
        protected void UpdateMaterials_Click(object sender, DirectEventArgs e)
        {

        }

        protected void cbRoomSelectIndex_Change(object sender, DirectEventArgs e)
        {
            grExport_Detail.GetStore().RemoveAll();
        }
        //----------Button-Windows---------------
        #region[Method]
        protected void GetData()
        {
            if (String.IsNullOrEmpty(SelectBoxExportRoom.Text) && String.IsNullOrEmpty(SelectBoxExportWarrehouse.Text))
            {
                DataTable dtExport = clsExport.BindGirdtb_Export(string.Empty);
                if (dtExport != null && dtExport.Rows.Count > 0)
                {
                    StoreExport.DataSource = dtExport;
                    StoreExport.DataBind();
                }
                else
                {
                    grExport.GetStore().RemoveAll();
                }
            }
            else
            {
                DataTable dtExport = clsExport.GetExportFillter(SelectBoxExportWarrehouse.SelectedItem.Value,
                    SelectBoxExportRoom.SelectedItem.Value);
                if (dtExport != null && dtExport.Rows.Count > 0)
                {
                    StoreExport.DataSource = dtExport;
                    StoreExport.DataBind();
                }
                else
                {
                    grExport.GetStore().RemoveAll();
                }
            }
        }
        private void GetExportFillterDate()
        {
            if (String.IsNullOrEmpty(txtDateBeginFillter.Text) && String.IsNullOrEmpty(txtDateEndFillter.Text))
            {
                DataTable dtExport = clsExport.BindGirdtb_Export(string.Empty);
                if (dtExport != null && dtExport.Rows.Count > 0)
                {
                    StoreExport.DataSource = dtExport;
                    StoreExport.DataBind();
                }
                else
                {
                    grExport.GetStore().RemoveAll();
                }
            }
            else
            {
                DataTable dtExport = clsExport.GetExportFillterDate(txtDateBeginFillter.Text, txtDateEndFillter.Text);
                if (dtExport != null && dtExport.Rows.Count > 0)
                {
                    StoreExport.DataSource = dtExport;
                    StoreExport.DataBind();
                }
                else
                {
                    grExport.GetStore().RemoveAll();
                }
            }
        }
        protected void GetExport_Materials(int id)
        {
            var clsExport_Materials = new Export_Detail_BLL();
            DataTable dtExport_Materials = clsExport_Materials.BindGirdtb_Export_Materials(id);
            if (dtExport_Materials != null && dtExport_Materials.Rows.Count > 0)
            {
                StoreExport_Detail.DataSource = dtExport_Materials;
                StoreExport_Detail.DataBind();
            }
        }
        protected void GetExport_Materials_Edit(int id)
        {
            var clsExport_Materials = new Export_Detail_BLL();
            StoreExport_Detail.DataSource = clsExport_Materials.BindGirdtb_Export_Materials_Edit(id);
            StoreExport_Detail.DataBind();
        }
        protected void DataDetail(int id)
        {
            DataTable dtExport = clsExport.BindGirdtb_ExportDetail(id);
            if (dtExport != null && dtExport.Rows.Count > 0)
            {
                cbBranch.SetValue(int.Parse(dtExport.Rows[0]["Branch_Id"].ToString()));
                cbWarehouse.SetValue(int.Parse(dtExport.Rows[0]["Warehouse_Id"].ToString()));
                if (String.IsNullOrEmpty(dtExport.Rows[0]["Room_ID"].ToString()) == false)
                {
                    cbRoom.SetValue(int.Parse(dtExport.Rows[0]["Room_ID"].ToString()));
                }
                txtExport_ID.Text = dtExport.Rows[0]["Export_ID"].ToString();
                txtExport_No.Text = dtExport.Rows[0]["Export_No"].ToString();
                txtExport_Date.Text = dtExport.Rows[0]["Export_Date"].ToString();
                txtProposed_Export_ID.Text = dtExport.Rows[0]["Proposed_Export_ID"].ToString();
                txtExport_Invoice.Text = dtExport.Rows[0]["Proposed_Export_No"].ToString();
                txtExport_Provider.Text = dtExport.Rows[0]["Export_Purcharse"].ToString();
                txtExport_Test.Text = dtExport.Rows[0]["Export_Test"].ToString();
                txtExport_Note.Text = dtExport.Rows[0]["Export_Note"].ToString();
            }
        }
        protected bool CheckInsert()
        {
            bool kiemtra = false;
            var Export = new Export_BLL();
            var dtExport = Export.BindGirdtb_Export(string.Empty);
            if (dtExport != null && dtExport.Rows.Count > 0)
            {
                foreach (DataRow dr in dtExport.Rows)
                {
                    if (txtExport_ID.Text != dr["Export_ID"].ToString())
                    {
                        if (txtExport_No.Text == dr["Export_No"].ToString())
                        {
                            kiemtra = true;
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Mã nhập kho đã tồn tại !");
                        }
                    }
                }
            }
            return kiemtra;
        }
        private void GetWarehouse()
        {
            var _dtWarehouse = _clsWarehouse.GetWarehouse();
            if (_dtWarehouse != null && _dtWarehouse.Rows.Count > 0)
            {
                StoreExportWarrehouse.DataSource = _dtWarehouse;
                StoreExportWarrehouse.DataBind();
            }
            else
            {
                SelectBoxExportWarrehouse.GetStore().RemoveAll();
            }
        }
        private void GetRoom()
        {
            var _dtRoom = _clsRoom.GetRoom(string.Empty);
            if (_dtRoom != null && _dtRoom.Rows.Count > 0)
            {
                StoreExportRoom.DataSource = _dtRoom;
                StoreExportRoom.DataBind();
            }
            else
            {
                SelectBoxExportRoom.GetStore().RemoveAll();
            }
        }
        #endregion
        #region [ComboBox]

        protected void GetComboBox()
        {
            var clsBranch = new Branch_BLL();
            DataTable dtBranch = clsBranch.Search(string.Empty);
            if (dtBranch != null && dtBranch.Rows.Count > 0)
            {
                BranchStore.DataSource = dtBranch;
                BranchStore.DataBind();
            }

            var clsWarehouse = new Warehouse_BLL();
            DataTable dtWarehouse = clsWarehouse.Search(string.Empty);
            if (dtWarehouse != null && dtWarehouse.Rows.Count > 0)
            {
                WarehouseStore.DataSource = dtWarehouse;
                WarehouseStore.DataBind();
            }

            var clsRoom = new Room_BLL();
            DataTable dtRoom = clsRoom.Search(string.Empty);
            if (dtRoom != null && dtRoom.Rows.Count > 0)
            {
                RoomStore.DataSource = dtRoom;
                RoomStore.DataBind();
            }
        }

        protected void BranchSelectIndex_Change(object sender, StoreReadDataEventArgs e)
        {
            cbWarehouse.ReadOnly = false;
            var clsKho = new Warehouse_BLL();
            if (cbBranch.SelectedItem.Value != null)
            {
                DataTable dtKho = clsKho.GetWarehouseBranch(int.Parse(cbBranch.SelectedItem.Value));
                if (dtKho != null && dtKho.Rows.Count > 0)
                {
                    WarehouseStore.DataSource = dtKho;
                    WarehouseStore.DataBind();
                }
                else
                {
                    cbBranch.Clear();
                    cbWarehouse.ReadOnly = true;
                    HTML.clsFormat.Alert_INFO("Thông báo", "Chi nhánh này không có kho vui lòng chọn chi nhánh khác !");
                }
            }
            else
            {
                cbBranch.Clear();
                cbWarehouse.ReadOnly = true;
                HTML.clsFormat.Alert_INFO("Thông báo", "Vui lòng chọn chi nhánh !");
            }
        }
        protected void WarehouseSelectIndex_Change(object sender, StoreReadDataEventArgs e)
        {
            cbRoom.ReadOnly = false;
            var clsRoom = new Room_BLL();
            if (cbWarehouse.SelectedItem.Value != null)
            {
                DataTable dtRoom = clsRoom.GetRoomWareHouse(int.Parse(cbWarehouse.SelectedItem.Value));
                if (dtRoom != null && dtRoom.Rows.Count > 0)
                {
                    RoomStore.DataSource = dtRoom;
                    RoomStore.DataBind();
                }
                else
                {
                    cbWarehouse.Clear();
                    cbRoom.ReadOnly = true;
                    HTML.clsFormat.Alert_INFO("Thông báo", "Kho này không có phòng chứa vui lòng chọn kho khác !");
                }
            }
            else
            {
                cbWarehouse.Clear();
                cbRoom.ReadOnly = true;
                HTML.clsFormat.Alert_INFO("Thông báo", "Vui lòng chọn kho !");
            }
        }

        protected void ReloadComboBox(object sender, StoreReadDataEventArgs e)
        {
            GetComboBox();
        }

        #endregion
        #region[ClearTextbox]
        protected void ClearTextBox()
        {
            FormPanelExport.Reset();

            txtExport_ID.Text = string.Empty;
            txtExport_No.Text = MaTuDong();
            txtExport_Date.Text = DateTime.Now.ToString();
        }
        #endregion
        #region[MaTangTuDong]
        protected string MaTuDong()
        {
            int i;
            DataTable dt = clsExport.BindGirdtb_Export(string.Empty);
            if (dt != null && dt.Rows.Count > 0)
            {
                int max = int.Parse(dt.Rows[0]["Export_ID"].ToString());
                for (i = 0; i < dt.Rows.Count; i++)
                {
                    if (int.Parse(dt.Rows[i]["Export_ID"].ToString()) > max)
                    {
                        max = int.Parse(dt.Rows[i]["Export_ID"].ToString());
                    }
                }
                i = max + 1;
            }
            else
            {
                i = 0;
            }
            return "XK_00" + i;
        }
        #endregion
        #region[Search]
        protected void Search_Event(object sender, DirectEventArgs e)
        {
            DataTable dtExport = clsExport.BindGirdtb_Export(txtSearch.Text);
            if (dtExport != null && dtExport.Rows.Count > 0)
            {
                StoreExport.DataSource = dtExport;
                StoreExport.DataBind();
            }
        }
        #endregion
        #region [Materials]
        void GetProposed_Export()
        {
            var clsProposed_Export = new Proposed_Export_BLL();
            Proposed_ExportStore.DataSource = clsProposed_Export.BindGirdtb_Proposed_Export_Materials_Still();
            Proposed_ExportStore.DataBind();
        }
        protected void GetProposed_Export_Materials()
        {
            var clsProposed_Export = new Proposed_Export_Detail_BLL();
            if (cbProposed_Export.SelectedItem.Value != null)
            {
                grExport_Detail.GetStore().RemoveAll();
                DataTable dtGetMaterialProposed_Export = clsProposed_Export.GetDataProposedQualityStill(int.Parse(cbProposed_Export.SelectedItem.Value), int.Parse(cbWarehouse.SelectedItem.Value));
                if (dtGetMaterialProposed_Export != null && dtGetMaterialProposed_Export.Rows.Count > 0)
                {
                    StoreExport_Proposed_Export_Materials.DataSource = dtGetMaterialProposed_Export;
                    StoreExport_Proposed_Export_Materials.DataBind();
                }
                else
                {
                    grExport_Proposed_Export_Materials.GetStore().RemoveAll();
                }
            }
            else
            {
                grExport_Detail.GetStore().RemoveAll();
                grExport_Proposed_Export_Materials.GetStore().RemoveAll();
            }
        }
        protected void btnSelectExport_Proposed_Export_Materials_Click(object sender, DirectEventArgs e)
        {
            var GetExport_Proposed_Export_Materials = e.ExtraParams["grExport_Proposed_Export_Materials"];
            var GetExport_Detail = e.ExtraParams["grExport_Detail"];

            var dtExport_Proposed_Export_Materials = JSON.Deserialize<DataTable>(GetExport_Proposed_Export_Materials);
            var dtExport_Detail = JSON.Deserialize<DataTable>(GetExport_Detail);

            foreach (DataRow rows in dtExport_Proposed_Export_Materials.Rows)
            {
                var insert = new Export_Detail_ET
                {
                    Export_ID = -1,
                    Materials_ID = int.Parse(rows["Materials_ID"].ToString()),
                    Materials_Alias = rows["Materials_Alias"].ToString(),
                    Materials_Name = rows["Materials_Name"].ToString(),
                    Unit_Name = rows["Unit_Name"].ToString(),
                    Export_Detail_Quality_Voucher = int.Parse(rows["Proposed_Export_Quality"].ToString()),
                    Export_Detail_Quality_HaveExport = 0,
                    Export_Detail_Quality_Still = int.Parse(rows["Proposed_Export_Quality_Still"].ToString()),
                    Export_Detail_Quality = -1,
                    Export_Detail_Quality_Insert = 0,
                    Export_Detail_Price = int.Parse(rows["Price_Initially"].ToString()),
                    SumMaterials = int.Parse(rows["SumMaterials"].ToString())
                };
                var kt = true;
                if (dtExport_Detail != null && dtExport_Detail.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtExport_Detail.Rows)
                    {
                        if (insert.Materials_ID.ToString() == dr["Materials_Id"].ToString())
                        {
                            kt = false;
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Sản phẩm đã tồn tại, vui lòng cập nhật số lượng !");
                        }
                    }
                }
                if (kt)
                {
                    StoreExport_Detail.Add(insert);
                    HTML.clsFormat.Alert_INFO("Thông báo", "Thêm sản phẩm thành công !");
                    txtProposed_Export_ID.Text = cbProposed_Export.SelectedItem.Value ?? string.Empty;
                    txtExport_Invoice.Text = cbProposed_Export.SelectedItem.Text;
                    WindowExport_Proposed_Export_Materials.Hide();
                    CheckboxSelectionModel2.ClearSelection();
                }
            }
        }
        protected void cbProposed_ExportSelectIndex_Change(object sender, DirectEventArgs e)
        {
            GetProposed_Export_Materials();
        }
        protected void StoreExport_Proposed_Export_Materials_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetProposed_Export_Materials();
        }
        #endregion
        #region[Permisstion]
        private void CheckPermisstion()
        {
            if (Session["login"] != null && Session["USer_Detail_Id"].ToString() != string.Empty)
            {
                bool Is_BtnAdd;
                bool Is_BtnEdit;
                bool Is_BtnView;
                bool Is_BtnDel;
                bool Is_BtnPrint;
                bool Is_BtnCancel;
                bool Is_BtnReview;

                SecurityServices.HasPermisstion_Btn(StringContent.Export, out Is_BtnAdd, out Is_BtnEdit, out Is_BtnDel, out Is_BtnView, out Is_BtnCancel, out Is_BtnPrint, out Is_BtnReview);
                if (Is_BtnAdd == false)
                {
                    btnAddNew.Visible = false;
                }
                if (Is_BtnEdit == false)
                {
                    btnEdit.Visible = false;
                }
                if (Is_BtnView == false)
                {
                    PanelExport.Visible = false;
                }
                if (Is_BtnDel == false)
                {
                    btnDel.Visible = false;
                }
                if (Is_BtnPrint == false)
                {
                    btnExport.Visible = false;
                }
            }
        }
        private bool CheckPermisstionDobclick()
        {
            var check = false;
            if (Session["login"] != null && Session["USer_Detail_Id"].ToString() != string.Empty)
            {
                bool Is_BtnAdd;
                bool Is_BtnEdit;
                bool Is_BtnView;
                bool Is_BtnDel;
                bool Is_BtnPrint;
                bool Is_BtnCancel;
                bool Is_BtnReview;

                SecurityServices.HasPermisstion_Btn(StringContent.Export, out Is_BtnAdd, out Is_BtnEdit, out Is_BtnDel, out Is_BtnView, out Is_BtnCancel, out Is_BtnPrint, out Is_BtnReview);
                if (Is_BtnEdit == false)
                {
                    check = true;
                }
            }
            return check;
        }
        #endregion

        private void WindowsBranch()
        {
            Window win = new Window()
            {
                ID = "WindowsBranch",
                Title = "Chi nhánh",
                Width = 829,
                Height = 400,
                Modal = true,
                AutoRender = false,
                Collapsible = false,
                Maximizable = true,
                Hidden = true,
                Loader = new ComponentLoader
                {
                    Url = "../PageParrent/Branch.aspx",
                    Mode = LoadMode.Frame,
                    LoadMask =
                    {
                        ShowMask = true
                    }
                }
            };
            this.Controls.Add(win);
        }
        private void WindowsWarehouse()
        {
            Window win = new Window()
            {
                ID = "WindowsWarehouse",
                Title = "Kho",
                Width = 829,
                Height = 400,
                Modal = true,
                AutoRender = false,
                Collapsible = false,
                Maximizable = true,
                Hidden = true,
                Loader = new ComponentLoader
                {
                    Url = "../PageParrent/Warehouse.aspx",
                    Mode = LoadMode.Frame,
                    LoadMask =
                    {
                        ShowMask = true
                    }
                }
            };
            this.Controls.Add(win);
        }
        private void WindowsRoom()
        {
            Window win = new Window()
            {
                ID = "WindowsRoom",
                Title = "Phòng chứa",
                Width = 829,
                Height = 400,
                Modal = true,
                AutoRender = false,
                Collapsible = false,
                Maximizable = true,
                Hidden = true,
                Loader = new ComponentLoader
                {
                    Url = "../PageParrent/Room.aspx",
                    Mode = LoadMode.Frame,
                    LoadMask =
                    {
                        ShowMask = true
                    }
                }
            };
            this.Controls.Add(win);
        }
    }
}